package com.briup.es.web;

import com.briup.es.config.response.Result;
import com.briup.es.domain.dto.OrderCreateDTO;
import com.briup.es.domain.vo.OrderDetailVO;
import com.briup.es.domain.vo.OrderVO;
import com.briup.es.service.OrderService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;

    @GetMapping("/")
    public Result<List<OrderVO>> getOrderList(Integer status) {
        List<OrderVO> orderVOS = orderService.queryOrderList(status);
        return Result.success(orderVOS);
    }

    @GetMapping("/{orderId}")
    public Result<OrderDetailVO> getOrderDetail(@PathVariable String orderId) {
        OrderDetailVO detailVO = orderService.queryOrderDetail(orderId);
        return Result.success(detailVO);
    }

    @PostMapping
    public Result<Void> addOrder(@RequestBody @Valid OrderCreateDTO orderCreateDTO) {
        orderService.addOrder(orderCreateDTO);
        return Result.success();
    }

    @PutMapping("/close/{orderId}")
    public Result<Void> cancelOrder(@PathVariable String orderId) {
        orderService.cancelOrder(orderId);
        return Result.success();
    }

    @PutMapping("/complete/{orderId}")
    public Result<Void> completeOrder(@PathVariable String orderId) {
        orderService.completeOrder(orderId);
        return Result.success();
    }
}
